﻿using Navigant.Infrastructure.DomainBase;
using Navigant.Infrastructure.RepositoryFramework;

namespace Navigant.Infrastructure.Cases
{
    public class CaseService<T> : Service<T> where T : IAggregateRoot
    {
        private ICase currentCase;
        private bool runWithElevatedPrivileges;

        protected CaseService(ICase currentCase)
            : this(currentCase, null)
        {
        }

        protected CaseService(ICase currentCase, IUnitOfWork unitOfWork) 
            : this(currentCase, unitOfWork, false)
        {
        }

        protected CaseService(ICase currentCase, IUnitOfWork unitOfWork, 
            bool runWithElevatedPrivileges)
            : base(unitOfWork)
        {
            this.currentCase = currentCase;
            this.runWithElevatedPrivileges = runWithElevatedPrivileges;
        }

        protected override IRepository<T> GetRepository()
        {
            return RepositoryFactory.GetRepository<IRepository<T>,
                T>(this.currentCase, this.UnitOfWork, this.runWithElevatedPrivileges);
        }

        protected ICase CurrentCase
        {
            get { return this.currentCase; }
        }

        protected bool RunWithElevatedPrivileges
        {
            get { return this.runWithElevatedPrivileges; }
        }
    }
}
